package com.maltys.dp.sequence;

/**
 * @author malty
 * @link <a href="https://leetcode.cn/problems/longest-increasing-subsequence/description/">最⻓递增⼦序列</a>
 */
public class LongestIncreasingSubsequence {
    public static void main(String[] args) {
        LongestIncreasingSubsequence lis = new LongestIncreasingSubsequence();
        int lengthOfLIS = lis.lengthOfLIS(new int[]{0, 1, 0, 3, 2, 3});
        System.out.println(lengthOfLIS);
    }

    public int lengthOfLIS(int[] nums) {
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int max = 1;
        for (int i = 1; i < nums.length; i++) {
            dp[i] = 1;
            for (int j = i - 1; j >= 0; j--) {
                if (nums[j] < nums[i]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            max = Math.max(max, dp[i]);
        }
        return max;
    }
}
